const _ = require('lodash');
const userInfoFacade = require('../../app/facade/userinfo.server.facade.js');
module.exports = {
    getByUserId : getByUserId,
    add: add
}

function getByUserId(req, res, next) {
    let params = req.params;
    let userInfoId = params.userInfoId;
    if (_.isEmpty(userInfoId)) {
        return next(new Error('userInfoId is empty'));
    } else {
    userInfoFacade.getByUserId(userInfoId, (error, result) => {
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
            // res.render('foodItem', result);
        }
    });
    }
}

function add(req, res, next) {
    let user = req.body;
    if (_.isEmpty(user)) {
        return next(new Error('user is empty'));
    } else {
    userInfoFacade.add(user, (error, result) => {
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
        }
    });
    }
}


